package com.corpdata.app.project.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.corpdata.app.project.dao.ProjectStationMapper;
import com.corpdata.app.project.entity.ProjectStation;
import com.corpdata.app.project.service.ProjectStationService;
import com.corpdata.common.result.Result;
import com.corpdata.common.result.util.ResultUtil;
import com.corpdata.common.utils.CorpdataUtil;
import com.corpdata.core.base.AbstractBaseService;

/**
 * 分区工位
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-08 15:23:00
 */
@Service
@Transactional
public class ProjectStationServiceImpl extends AbstractBaseService<ProjectStation> implements ProjectStationService {
	
	@Autowired
	private ProjectStationMapper projectStationMapper;
	
	public Result insert(String partitionId,String StationNames){
		Result ret=null;
		String[] names=StationNames.split(",");
		for(String name:names){
			ProjectStation record=new ProjectStation();
			record.setId(CorpdataUtil.getUUID());
			record.setFkPartition(partitionId);
			record.setStationName(name);
			record.setStationState(0);
			ret=super.save(record);
		}
		return ret;
		
	}
	
	public Result deleteByPartitionId(String id){
		if(projectStationMapper.deleteByPartitionId(id)>0){
    		return ResultUtil.success();
    	}else{
    		return ResultUtil.fail();
    	}
	}

	@Override
	public List<ProjectStation> findAll(Map<String,Object> params) {
		return projectStationMapper.selectAll(params );
	}

	@Override
	public int updateProjectStation(String fkTeam,String stationState, List<String> idList) {
		return projectStationMapper.updateProjectStation(fkTeam,stationState,idList);
	}

	@Override
	public int toTuizuStatus(String fkTeam) {
		return projectStationMapper.toTuizuStatus(fkTeam);
	}
	//获取工位个数
	@Override
	public int getStationCount(Map<String, Object> params) {
		return projectStationMapper.getStationCount(params);
	}
	
	public int selectAll(String teamId){
		Map<String,Object> params = new HashMap<String,Object>();
		if(null !=teamId && !("").equals(teamId)){
			params.put("teamId",teamId );
		}
		
		return projectStationMapper.selectCount(params);
	}
}
